package worldinruin.core.imp.battle;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Random;

import worldinruin.utils.IObservable;

public class Dice implements IObservable {
	
	private Random random = new Random();
	private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
	private int spots;
	
	/**
	 * Rolls the dice and returns the value on the dice.
	 * @return Dice value.
	 */
	public int roll(){		
		pcs.firePropertyChange("dice roll", spots, spots = random.nextInt(6) + 1 );
		return spots;
	}

	@Override
	public void addPropertyChangeListener(PropertyChangeListener observer) {
		pcs.addPropertyChangeListener(observer);
		
	}

	@Override
	public void removePropertyChangeListener(PropertyChangeListener observer) {
		pcs.removePropertyChangeListener(observer);
		
	}

}
